package zhtt;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import zhtt.demo01.BlogMapper;

import java.io.InputStream;

/**
 * Created by mengxiaxia on 2017/4/22.
 */
public class SessionFactoryUtil2 {


        private static final String MYBATIS_CONFIG_PATH = "Configuration.xml";

        private static InputStream is = null;

        private static SqlSessionFactory sqlSessionFactory2 = null;

        static {
            try{
                is = Resources.getResourceAsStream(MYBATIS_CONFIG_PATH);
                SqlSessionFactoryBuilder sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder();
                /*这个是<environment id="test">*/
                sqlSessionFactory2 = sqlSessionFactoryBuilder.build(is, "zhtt");
            }catch (Exception e){
                e.printStackTrace();
            }

        }
        /**
         */
        private SessionFactoryUtil2(){};


        /**
         * @return SqlSessionFactory
         */
        public static SqlSessionFactory getSqlSessionFactoryIntance2(){

            return sqlSessionFactory2;

        }

        /**
         * @return SqlSession
         */
        public static SqlSession getSqlSessionIntance2() {
            return sqlSessionFactory2.openSession();
        }

}
